package com.lingchen.controller;

import com.lingchen.entity.Collect;
import com.lingchen.entity.Error;
import com.lingchen.response.Result;
import com.lingchen.response.ResultUtil;
import com.lingchen.service.CollectService;
import com.lingchen.service.ErrorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Author    zhangshuai
 * Email     838878458@qq.com
 * Time      2018/2/28
 * Function  错题集
 */
@Controller
@RequestMapping("error/")
public class ErrorController {
    @Autowired
    private ErrorService errorService;

    @RequestMapping(value = "add", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> add(@RequestBody List<Error> errors) {
        errorService.insertError(errors.toArray(new Error[]{}));
        return ResultUtil.success();
    }

    @RequestMapping(value = "index", method = RequestMethod.GET)
    public String index(Long userName, String courseId, Model model) {
        model.addAttribute("list", errorService.selectError(userName, courseId));
        return "collect";
    }

}
